home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / postfix / post-install < prev    next >
Encoding:
Text File  |  2004-03-26  |  17.6 KB  |  550 lines

  1. #!/usr/bin/bash
  2.  
  3. # To view the formatted manual page of this file, type:
  4. #    POSTFIXSOURCE/mantools/srctoman - post-install | nroff -man
  5.  
  6. #++
  7. # NAME
  8. #    post-install
  9. # SUMMARY
  10. #    Postfix post-installation script
  11. # SYNOPSIS
  12. #    post-install [name=value] command ...
  13. # DESCRIPTION
  14. #    The post-install script performs the finishing touch of a Postfix
  15. #    installation, after the executable programs and configuration
  16. #    files are installed. Usage is one of the following:
  17. # .IP o
  18. #    While installing Postfix from source code on the local machine, the
  19. #    script is run by the postfix-install script to update selected file
  20. #    or directory permissions and to update Postfix configuration files.
  21. # .IP o
  22. #    While installing Postfix from a pre-built package, the script is run
  23. #    by the package management procedure to set all file or directory
  24. #    permissions and to update Postfix configuration files.
  25. # .IP o
  26. #    The script can be used to change installation parameter settings such
  27. #    as mail_owner or setgid_group after Postfix is already installed.
  28. # .IP o
  29. #    The script can be used to upgrade configuration files and to upgrade
  30. #    file/directory permissions of a secondary Postfix instance.
  31. # .IP o
  32. #    At Postfix start-up time, the script is run from "postfix check" to
  33. #    create missing queue directories.
  34. # .PP
  35. #    The post-install script is controlled by installation parameters.
  36. #    Specific parameters are described at the end of this document.
  37. #    All installation parameters must be specified ahead of time via
  38. #    one of the methods described below.
  39. #
  40. #    Arguments
  41. # .IP create-missing
  42. #    Create missing queue directories with ownerships and permissions
  43. #    according to the contents of $config_directory/postfix-files, using
  44. #    the mail_owner and setgid_group parameter settings from the command
  45. #    line, process environment or from the installed main.cf file.
  46. #
  47. #    This is required at Postfix start-up time.
  48. # .IP set-permissions
  49. #    Set all file/directory ownerships and permissions according to the
  50. #    contents of $config_directory/postfix-files, using the mail_owner
  51. #    and setgid_group parameter settings from the command line, process
  52. #    environment or from the installed main.cf file. Implies create-missing.
  53. #
  54. #    This is required when installing Postfix from a pre-built package,
  55. #    or when changing the mail_owner or setgid_group installation parameter
  56. #    settings after Postfix is already installed.
  57. # .IP upgrade-permissions
  58. #    Update ownership and permission of existing files/directories as
  59. #    specified in $config_directory/postfix-files, using the mail_owner
  60. #    and setgid_group parameter settings from the command line, process
  61. #    environment or from the installed main.cf file. Implies create-missing.
  62. #
  63. #    This is required when upgrading an existing Postfix instance.
  64. # .IP upgrade-configuration
  65. #    Edit the installed main.cf and master.cf files, in order to account
  66. #    for missing services and to fix deprecated parameter settings.
  67. #
  68. #    This is required when upgrading an existing Postfix instance.
  69. # .IP upgrade-source
  70. #    Short-hand for: upgrade-permissions upgrade-configuration.
  71. #
  72. #    This is recommended when upgrading Postfix from source code.
  73. # .IP upgrade-package
  74. #    Short-hand for: set-permissions upgrade-configuration.
  75. #
  76. #    This is recommended when upgrading Postfix from a pre-built package.
  77. # .IP first-install-reminder
  78. #    Remind the user that they still need to configure main.cf and the
  79. #    aliases file, and that newaliases still needs to be run.
  80. #
  81. #    This is recommended when Postfix is installed for the first time.
  82. # MULTIPLE POSTFIX INSTANCES
  83. # .ad
  84. # .fi
  85. #    Multiple Postfix instances on the same machine can share command and
  86. #    daemon program files but must have separate configuration and queue
  87. #    directories.
  88. #
  89. #    To create a secondary Postfix installation on the same machine,
  90. #    copy the configuration files from the primary Postfix instance to
  91. #    a secondary configuration directory and execute:
  92. #
  93. #    post-install config_directory=secondary-config-directory \e
  94. # .in +4
  95. #        queue_directory=secondary-queue-directory \e
  96. # .br
  97. #        create-missing
  98. # .PP
  99. #    This creates secondary Postfix queue directories, sets their access
  100. #    permissions, and saves the specified installation parameters to the
  101. #    secondary main.cf file.
  102. #
  103. #    Be sure to list the secondary configuration directory in the
  104. #    alternate_config_directories parameter in the primary main.cf file.
  105. #
  106. #    To upgrade a secondary Postfix installation on the same machine,
  107. #    execute:
  108. #
  109. #    post-install config_directory=secondary-config-directory \e
  110. # .in +4
  111. #        upgrade-permissions upgrade-configuration
  112. # INSTALLATION PARAMETER INPUT METHODS
  113. # .ad
  114. # .fi
  115. #    Parameter settings can be specified through a variety of
  116. #    mechanisms.  In order of decreasing precedence these are:
  117. # .IP "command line"
  118. #    Parameter settings can be given as name=value arguments on
  119. #    the post-install command line. These have the highest precedence.
  120. #    Settings that override the installed main.cf file are saved.
  121. # .IP "process environment"
  122. #    Parameter settings can be given as name=value environment
  123. #    variables.
  124. #    Settings that override the installed main.cf file are saved.
  125. # .IP "installed configuration files"
  126. #    If a parameter is not specified via the command line or via the
  127. #    process environment, post-install will attempt to extract its
  128. #    value from the already installed Postfix main.cf configuration file.
  129. #    These settings have the lowest precedence.
  130. # INSTALLATION PARAMETER DESCRIPTION
  131. # .ad
  132. # .fi
  133. #    The description of installation parameters is as follows:
  134. # .IP config_directory
  135. #    The directory for Postfix configuration files.
  136. # .IP daemon_directory
  137. #    The directory for Postfix daemon programs. This directory
  138. #    should not be in the command search path of any users.
  139. # .IP command_directory
  140. #    The directory for Postfix administrative commands. This
  141. #    directory should be in the command search path of adminstrative users.
  142. # .IP queue_directory
  143. #    The directory for Postfix queues.
  144. # .IP sendmail_path
  145. #    The full pathname for the Postfix sendmail command.
  146. #    This is the Sendmail-compatible mail posting interface.
  147. # .IP newaliases_path
  148. #    The full pathname for the Postfix newaliases command.
  149. #    This is the Sendmail-compatible command to build alias databases
  150. #    for the Postfix local delivery agent.
  151. # .IP mailq_path
  152. #    The full pathname for the Postfix mailq command.
  153. #    This is the Sendmail-compatible command to list the mail queue.
  154. # .IP mail_owner
  155. #    The owner of the Postfix queue. Its numerical user ID and group ID
  156. #    must not be used by any other accounts on the system.
  157. # .IP setgid_group
  158. #    The group for mail submission and for queue management commands.
  159. #    Its numerical group ID must not be used by any other accounts on the
  160. #    system, not even by the mail_owner account.
  161. # .IP manpage_directory
  162. #    The directory for the Postfix on-line manual pages.
  163. # .IP sample_directory
  164. #    The directory for the Postfix sample configuration files.
  165. # .IP readme_directory
  166. #    The directory for the Postfix README files.
  167. # SEE ALSO
  168. #    postfix-install(1) Postfix primary installation script.
  169. # FILES
  170. #    $config_directory/main.cf, Postfix installation parameters.
  171. #    $config_directory/postfix-files, installation control file.
  172. #    $config_directory/install.cf, obsolete configuration file.
  173. # LICENSE
  174. # .ad
  175. # .fi
  176. #    The Secure Mailer license must be distributed with this software.
  177. # AUTHOR(S)
  178. #    Wietse Venema
  179. #    IBM T.J. Watson Research
  180. #    P.O. Box 704
  181. #    Yorktown Heights, NY 10598, USA
  182. #--
  183.  
  184. umask 022
  185.  
  186. #PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
  187. SHELL=/bin/sh
  188. IFS="     
  189. "
  190. BACKUP_IFS="$IFS"
  191.  
  192. USAGE="Usage: $0 [name=value] command
  193.     create-missing          Create missing queue directories.
  194.     upgrade-source          When installing or upgrading from source code.
  195.     upgrade-package         When installing or upgrading from pre-built package.
  196.     first-install-reminder  Remind of mandatory first-time configuration steps.
  197.     name=value              Specify an installation parameter".
  198.  
  199. # Process command-line options and parameter settings. Work around
  200. # brain damaged shells. "IFS=value command" should not make the
  201. # IFS=value setting permanent. But some broken standard allows it.
  202.  
  203. create=; set_perms=; upgrade_perms=; upgrade_conf=; first_install_reminder=
  204.  
  205. for arg
  206. do
  207.     case $arg in
  208.                 *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
  209.      create-missing) create=1;;
  210.       set-perm*) create=1; set_perms=1;;
  211.       upgrade-perm*) create=1; upgrade_perms=1;;
  212.       upgrade-conf*) upgrade_conf=1;;
  213.      upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
  214.     upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
  215.      first-install*) first_install_reminder=1;;
  216.           *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
  217.     esac
  218.     shift
  219. done
  220.  
  221. # Sanity checks.
  222.  
  223. test -n "$create$upgrade_conf$first_install_reminder" || {
  224.     echo "$0: Error: $USAGE" 1>&2
  225.     exit 1
  226. }
  227.  
  228. # Bootstrapping problem.
  229.  
  230. if [ -n "$command_directory" ]
  231. then
  232.     POSTCONF="$command_directory/postconf"
  233. else
  234.     POSTCONF="postconf"
  235. fi
  236.  
  237. $POSTCONF -d mail_version >/dev/null 2>/dev/null || {
  238.     echo $0: Error: no $POSTCONF command found. 1>&2
  239.     echo Re-run this command as $0 command_directory=/some/where. 1>&2
  240.     exit 1
  241. }
  242.  
  243. test -n "$config_directory" ||
  244.     config_directory=`$POSTCONF -d -h config_directory` || exit 1
  245.  
  246. test -d "$config_directory" || {
  247.     echo $0: Error: $config_directory is not a directory. 1>&2
  248.     exit 1
  249. }
  250.  
  251. test -f $config_directory/postfix-files || {
  252.     echo $0: Error: $config_directory/postfix-files is not a file. 1>&2
  253.     exit 1
  254. }
  255.  
  256. #
  257. # LINUX by default does not synchronously update directories -
  258. # that's dangerous for mail.
  259. #
  260. if [ -f /usr/bin/chattr ]
  261. then
  262.     CHATTR="/usr/bin/chattr +S"
  263. else
  264.     CHATTR=echo
  265. fi
  266.  
  267. case `uname -s` in
  268. HP-UX*) FMT=cat;;
  269.      *) FMT=fmt;;
  270. esac
  271.  
  272. # If a parameter is not set via the command line or environment,
  273. # try to use settings from installed configuration files.
  274.  
  275. # Extract parameter settings from the obsolete install.cf file, as
  276. # a transitional aid.
  277.  
  278. grep setgid_group $config_directory/main.cf >/dev/null 2>&1 || {
  279.     test -f $config_directory/install.cf  && {
  280.         for name in sendmail_path newaliases_path mailq_path setgid manpages
  281.         do
  282.     eval junk=\$$name
  283.         case "$junk" in
  284.         "") eval unset $name;;
  285.         esac
  286.        eval : \${$name="\`. $config_directory/install.cf; echo \$$name\`"} \
  287.         || exit 1
  288.         done
  289.         : ${setgid_group=$setgid}
  290.         : ${manpage_directory=$manpages}
  291.     }
  292. }
  293.  
  294. # Extract parameter settings from the installed main.cf file.
  295.  
  296. test -f $config_directory/main.cf && {
  297.     for name in daemon_directory command_directory queue_directory mail_owner \
  298.         setgid_group sendmail_path newaliases_path mailq_path \
  299.     manpage_directory sample_directory readme_directory
  300.     do
  301.     eval junk=\$$name
  302.         case "$junk" in
  303.         "") eval unset $name;;
  304.         esac
  305.         eval : \${$name=\`$POSTCONF -c $config_directory -h $name\`} || exit 1
  306.     done
  307. }
  308.  
  309. # Sanity checks
  310.  
  311. case $manpage_directory in
  312.  no) echo $0: Error: manpage_directory no longer accepts \"no\" values. 1>&2
  313.      echo Try again with \"$0 manpage_directory=/pathname ...\". 1>&2; exit 1;;
  314. esac
  315.  
  316. case $setgid_group in
  317.  no) echo $0: Error: setgid_group no longer accepts \"no\" values. 1>&2
  318.      echo Try again with \"$0 setgid_group=groupname ...\" 1>&2; exit 1;;
  319. esac
  320.  
  321. for path in "$daemon_directory" "$command_directory" "$queue_directory" \
  322.     "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory" \
  323.     "$sample_directory"
  324. do
  325.    case "$path" in
  326.    /*) ;;
  327.     *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
  328.    esac
  329. done
  330.  
  331. for path in "$readme_directory"
  332. do
  333.    case "$path" in
  334.    /*) ;;
  335.    no) ;;
  336.     *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2; exit 1;;
  337.    esac
  338. done
  339.  
  340. # Find out what parameters were not specified via command line,
  341. # via environment, or via installed configuration files.
  342.  
  343. missing=
  344. for name in daemon_directory command_directory queue_directory mail_owner \
  345.     setgid_group sendmail_path newaliases_path mailq_path manpage_directory \
  346.     sample_directory readme_directory
  347. do
  348.     eval test -n \"\$$name\" || missing="$missing $name"
  349. done
  350.  
  351. # All parameters must be specified at this point.
  352.  
  353. test -n "$non_interactive" -a -n "$missing" && {
  354.     cat <<EOF | ${FMT} 1>&2
  355. $0: Error: some required installation parameters are not defined.
  356.  
  357. - Either the parameters need to be given in the $config_directory/main.cf
  358. file from a recent Postfix installation,
  359.  
  360. - Or the parameters need to be specified through the process
  361. environment.
  362.  
  363. - Or the parameters need to be specified as name=value arguments
  364. on the $0 command line,
  365.  
  366. The following parameters were missing:
  367.  
  368.     $missing
  369.  
  370. EOF
  371.     exit 1
  372. }
  373.  
  374. POSTCONF="$command_directory/postconf"
  375.  
  376. # Save settings, allowing command line/environment override.
  377.  
  378. override=
  379. for name in daemon_directory command_directory queue_directory mail_owner \
  380.     setgid_group sendmail_path newaliases_path mailq_path manpage_directory \
  381.     sample_directory readme_directory
  382. do
  383.     eval test \"\$$name\" = \"`$POSTCONF -c $config_directory -h $name`\" || {
  384.     override=1
  385.     break
  386.     }
  387. done
  388.  
  389. test -n "$override" && {
  390.     $POSTCONF -c $config_directory -e \
  391.     "daemon_directory = $daemon_directory" \
  392.     "command_directory = $command_directory" \
  393.     "queue_directory = $queue_directory" \
  394.     "mail_owner = $mail_owner" \
  395.     "setgid_group = $setgid_group" \
  396.     "sendmail_path = $sendmail_path" \
  397.     "mailq_path = $mailq_path" \
  398.     "newaliases_path = $newaliases_path" \
  399.     "manpage_directory = $manpage_directory" \
  400.     "sample_directory = $sample_directory" \
  401.     "readme_directory = $readme_directory" \
  402.     || exit 1
  403. }
  404.  
  405. # Use file/directory status information in $config_directory/postfix-files.
  406.  
  407. test -n "$create" && {
  408.     exec <$config_directory/postfix-files || exit 1
  409.     while IFS=: read path type owner group mode flags junk
  410.     do
  411.     IFS="$BACKUP_IFS"
  412.     set_permission=
  413.     # Skip comments.
  414.     case $path in
  415.     [$]*) ;;
  416.        *) continue;;
  417.     esac
  418.     # Expand $name, and canonicalize null fields.
  419.     for name in path owner group flags
  420.     do
  421.         eval junk=\${$name}
  422.         case $junk in
  423.         [$]*) eval $name=$junk;;
  424.            -) eval $name=;;
  425.            *) ;;
  426.         esac
  427.     done
  428.     # Skip uninstalled files.
  429.     case $path in
  430.     no|no/*) continue;;
  431.     esac
  432.     # Pick up the flags.
  433.     case $flags in *u*) upgrade_flag=1;; *) upgrade_flag=;; esac
  434.     case $flags in *c*) create_flag=1;; *) create_flag=;; esac
  435.     case $flags in *r*) recursive="-R";; *) recursive=;; esac
  436.     # Create missing directories with proper owner/group/mode settings.
  437.     if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
  438.     then
  439.         mkdir $path || exit 1
  440.         $CHATTR $path >/dev/null 2>/dev/null
  441.         set_permission=1
  442.     # Update all owner/group/mode settings.
  443.     elif [ -n "$set_perms" ]
  444.     then
  445.         set_permission=1
  446.     # Update obsolete owner/group/mode settings.
  447.     elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
  448.     then
  449.         set_permission=1
  450.     fi
  451.     test -n "$set_permission" && {
  452.         chown $recursive $owner $path || exit 1
  453.         test -z "$group" || chgrp $recursive $group $path || exit 1
  454.         chmod $mode $path || exit 1
  455.     }
  456.     done
  457. }
  458.  
  459. # Upgrade existing Postfix configuration files if necessary.
  460.  
  461. test -n "$upgrade_conf" && {
  462.  
  463.     # Add missing flush service to master.cf.
  464.  
  465.     grep 'flush.*flush' $config_directory/master.cf >/dev/null || {
  466.     echo Editing $config_directory/master.cf, adding missing entry for flush service
  467.     cat >>$config_directory/master.cf <<EOF || exit 1
  468. flush     unix  -       -       n       1000?   0       flush
  469. EOF
  470.     }
  471.  
  472.     # Change privileged pickup service into unprivileged.
  473.  
  474.     grep "^pickup[     ]*fifo[     ]*n[     ]*n" \
  475.     $config_directory/master.cf >/dev/null && {
  476.         echo Editing $config_directory/master.cf, making the pickup service unprivileged
  477.         ed $config_directory/master.cf <<EOF || exit 1
  478. /^pickup[     ]*fifo[     ]*n[     ]*n/
  479. s/\(n[     ]*\)n/\1-/
  480. p
  481. w
  482. q
  483. EOF
  484.     }
  485.  
  486.     # Change private cleanup and flush services into public.
  487.  
  488.     for name in cleanup flush
  489.     do
  490.     grep "^$name[     ]*unix[     ]*[-y]" \
  491.         $config_directory/master.cf >/dev/null && {
  492.         echo Editing $config_directory/master.cf, making the $name service public
  493.         ed $config_directory/master.cf <<EOF || exit 1
  494. /^$name[     ]*unix[     ]*[-y]/
  495. s/[-y]/n/
  496. p
  497. w
  498. q
  499. EOF
  500.     }
  501.     done
  502.  
  503.     # With 10000 active queue files, the active queue directory should
  504.     # be hashed, and so should the other directories, because they
  505.     # can contain even more mail.
  506.     #
  507.     # Unfortunately, this sucks mailq performance on unloaded systems.
  508.     #
  509.     # If you don't want slow mailq, be sure to hash defer and deferred,
  510.     # because those two directories can contain lots of files.
  511.  
  512.     found=`$POSTCONF -c $config_directory -h hash_queue_names`
  513.     missing=
  514.     (echo "$found" | grep active >/dev/null) || missing="$missing active"
  515.     (echo "$found" | grep bounce >/dev/null) || missing="$missing bounce"
  516.     (echo "$found" | grep defer >/dev/null)  || missing="$missing defer"
  517.     (echo "$found" | grep flush >/dev/null)  || missing="$missing flush"
  518.     (echo "$found" | grep incoming>/dev/null)|| missing="$missing incoming"
  519.     (echo "$found" | grep deferred>/dev/null)|| missing="$missing deferred"
  520.     test -n "$missing" && {
  521.     echo fixing main.cf hash_queue_names for missing $missing
  522.     $POSTCONF -c $config_directory -e hash_queue_names="$found$missing" ||
  523.         exit 1
  524.     }
  525. }
  526.  
  527. # A reminder if this is the first time Postfix is being installed.
  528.  
  529. test -n "$first_install_reminder" && {
  530.  
  531.     ALIASES=`$POSTCONF -h alias_database | sed 's/^[^:]*://'`
  532.     NEWALIASES_PATH=`$POSTCONF -h newaliases_path`
  533.     cat <<EOF | ${FMT}
  534.  
  535.     Warning: you still need to edit myorigin/mydestination/mynetworks
  536.     parameter settings in $config_directory/main.cf.
  537.  
  538.     See also http://www.postfix.org/faq.html for information about
  539.     dialup sites or about sites inside a firewalled network.
  540.  
  541.     BTW: Check your $ALIASES file and be sure to set up aliases
  542.     that send mail for root and postmaster to a real person, then
  543.     run $NEWALIASES_PATH.
  544.  
  545. EOF
  546.  
  547. }
  548.  
  549. exit 0
  550.